home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  10.1 KB  |  354 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/DTR/RCS/display.c,v 1.0 92/01/06 17:43:03 drapeau Exp Locker: derek $ */
  25. /* $Log:    display.c,v $
  26.  * Revision 1.0  92/01/06  17:43:03  drapeau
  27.  * Made a number of cosmetic changes to make code easier to read and
  28.  * to conform to programming specifications.
  29.  * 
  30.  * Revision 0.25  91/09/24  16:49:10  derek
  31.  * Zoom level's max value is changed from 50 to 4.
  32.  * 
  33.  * Revision 0.24  91/09/18  22:47:16  derek
  34.  * The following things are done:
  35.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  36.  * 2.    Copyright messages included.
  37.  * 3.    Some minor bugs fixed.
  38.  * 
  39.  * Revision 0.23  91/08/21  17:46:58  derek
  40.  * The big canvas "mis-placed" bug is fixed.
  41.  * 
  42.  * Revision 0.22  91/08/21  11:34:09  derek
  43.  * The following changes are made:
  44.  * 1.    Now the duration and size of the recorded sound will be displayed
  45.  *     during recording.
  46.  * 2.    I have changed GetSelection() corresponding to the request of Tek joo
  47.  * 3.    Info Panel is added to the application.
  48.  * 4.    Fixed SizeToFitHandler() so that when no file or buffer is currently
  49.  *     loaded, it would not do anything (except giving a warning
  50.  *     notice_prompt).
  51.  * 5.    Inplemented the `Close' Menu option in the document menu.
  52.  * 6.    Fixed the bug in which after ClearAll and I press PreviewEdit,
  53.  *     the edit wont be played.
  54.  * 7.    I have made the changes corresponding to the change in OpenPanel's
  55.  *     name.  (from OpenPanel to Browse).
  56.  * 8.    Incorporated BrowseCheck to check command line arg.
  57.  * 9.    Changed most EditingStatusMessages to NoticePrompts.
  58.  * 10.    SoundFileSaveAsPopUp and EditListSaveAsPopUp are removed 
  59.  *     from the application.
  60.  * 
  61.  * Revision 0.21  91/08/16  18:08:38  derek
  62.  * 
  63.  * The following things are done:
  64.  * 1.    I have fixed an openpanel bug in my code in which I 
  65.  *     made the app return the wrong values to OpenHandler and
  66.  *     the SaveHandler.
  67.  * 2.    The flashing color of the play button has been changed from
  68.  *     Red to Green.
  69.  * 3.    Fixed a quantization bug: Buffer.play.end, when converted
  70.  *     from endingTimeInSec, should not exceed Buffer_hdr_data_size - 1.
  71.  * 
  72.  * Revision 0.20  91/08/14  18:43:46  derek
  73.  * I fixed a UpdateSpaceOnTmp() bug.
  74.  * 
  75.  * Revision 0.19  91/08/14  18:14:49  derek
  76.  * The following things are done:
  77.  * 1.    I changed the name of the "save as" and "save" menu options
  78.  *     to be more specific.  ie. to "save sound file" and "save edit list".
  79.  * 2.    I removed the preview panel popup and replaced it with a preview
  80.  *     edit button.
  81.  * 3.    I changed the message displayed by UpdateSpaceOnTmp() to consist
  82.  *     only of the time remaining and the amount of space left.  There is
  83.  *     no more percentage indicating the capacity of /usr/tmp.
  84.  * 
  85.  * Revision 0.18  91/08/13  20:38:21  derek
  86.  * The buttons (play, pause, record) will now flash after they are pressed.
  87.  * This only applies to times when audio files (not edit-lists) are 
  88.  * played.
  89.  * 
  90.  * Revision 0.17  91/08/08  11:02:02  derek
  91.  * This is a cleaner version.  I have removed lots of printf/fprintf 
  92.  * statements from it, and have also cleaned up the code using xsaber.
  93.  * This version should run substantially faster.
  94.  * 
  95.  * Revision 0.16  91/08/07  16:23:59  derek
  96.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  97.  * 
  98.  * Revision 0.15  91/07/31  14:50:54  derek
  99.  * I have changed the user interface so that text fields like size and
  100.  * duration will be displayed in normal (not bold) format.   I also fixed
  101.  * a network bug.  In addition, I have added a routine to check how
  102.  * much disk space is left in /usr/tmp.
  103.  * 
  104.  * Revision 0.14  91/07/29  15:10:10  derek
  105.  * The playing w/o stopping error is fixed.
  106.  * 
  107.  * Revision 0.13  91/06/26  15:55:00  derek
  108.  * I have reformatted the code to conform coding specs.
  109.  * 
  110.  * Revision 0.12  91/06/25  11:38:04  derek
  111.  * I have added the new protocol items.
  112.  * 
  113.  * Revision 0.11  91/06/20  19:55:17  derek
  114.  * The network part should be working.  Also fixed numerous minor parts
  115.  * involving the canvas and the display.
  116.  *  */
  117. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/display.c,v 1.0 92/01/06 17:43:03 drapeau Exp Locker: derek $";
  118.  
  119. #include "dtr.h"
  120. #include "dtr_ui.h"
  121.  
  122. extern dtr_mainWindow_objects*        dtr_mainWindow;
  123. extern dtr_editListPanelPopUp_objects*    dtr_editListPanelPopUp;
  124.  
  125. void
  126.   InitDisplay()
  127. {
  128.   xv_set(dtr_mainWindow->playGain, PANEL_VALUE,                /* Set the Play and Record Slider volume, and also the... */
  129.      Audio_state.play.gain, NULL);                    /* ...editListVolume Slider. */
  130.   xv_set(dtr_editListPanelPopUp->editListVolumeSlider,
  131.      PANEL_VALUE, Audio_state.play.gain, NULL);
  132.   xv_set(dtr_mainWindow->recordGain, PANEL_VALUE, 
  133.      Audio_state.record.gain, NULL);
  134.   BlackColorIndex = gcm_color_index("black");
  135.   RedColorIndex   = gcm_color_index("red");
  136.   GreenColorIndex = gcm_color_index("green");
  137.   UpdateSpaceOnTmp();
  138. }
  139.  
  140. /*
  141.  *  Show the duration of the whole sound buffer.
  142.  */
  143. void
  144.   DisplaySoundDuration()
  145. {
  146.   double   timeInSec;
  147.   int      minute;
  148.   double   second;
  149.   int      size;
  150.   
  151.   size = (int) Buffer.hdr.data_size;
  152.   if (size < 0)  
  153.   {
  154.     fprintf(stderr, "Error:  Negative selection size.\n");
  155.     exit(0);
  156.   }
  157.   timeInSec = Buffer.hdr.data_size / (double) DEVICE_SAMPLE_RATE;
  158.   minute = irint(floor(timeInSec / 60.0));
  159.   second = timeInSec - (60.0 * minute);
  160.   sprintf(msg, " %d min %.2lf sec.", minute, second);
  161.   Alert(dtr_mainWindow->durationMessage, msg);
  162. }
  163.  
  164. /*
  165.  *  Show the duration of the selected (highlighted) area.
  166.  */
  167. void
  168.   DisplaySoundSelectionDuration()
  169. {
  170.   double   timeInSec;
  171.   int      minute;
  172.   double   second;
  173.   int      size;
  174.   
  175.   size = (int) Buffer.play.end - (int) Buffer.play.start;
  176.   if (size < 0)  
  177.   {
  178.     fprintf(stderr, "Error:  Negative selection size.\n");
  179.     exit(0);
  180.   }
  181.   timeInSec = size / (double) DEVICE_SAMPLE_RATE;
  182.   minute = irint(floor(timeInSec / 60.0));
  183.   second = timeInSec - (60.0 * minute);
  184.   sprintf(msg, "   %d min  %.2lf sec.", minute, second);
  185.   Alert(dtr_mainWindow->selectionDurationMessage, msg);
  186. }
  187.  
  188.  
  189. /*
  190.  *  Show the size of the whole buffer.
  191.  */
  192. void
  193.   DisplaySoundSize()
  194. {
  195.   int    size;
  196.   
  197.   size = (int) Buffer.hdr.data_size;
  198.   if (size < 0)  
  199.   {
  200.     fprintf(stderr, "Error:  Negative selection size");
  201.     exit(0);
  202.   }
  203.   if (size > 100000) 
  204.   {
  205.     sprintf(msg, " %d bytes  (%.1f MB)", size, size/1000000.0);
  206.   }
  207.   else 
  208.   {
  209.     sprintf(msg, "  %d bytes  (%.1f KB)", size, size/1000.0);
  210.   }
  211.   Alert(dtr_mainWindow->sizeMessage, msg);
  212. }
  213.  
  214.  
  215. /*
  216.  *  Show the size of the selected (highlighted) area.
  217.  */
  218. void
  219.   DisplaySoundSelectionSize()
  220. {
  221.   int    size;
  222.   
  223.   size = (int) Buffer.play.end - (int) Buffer.play.start + 1;
  224.   if (size < 0)  
  225.   {
  226.     fprintf(stderr, "Error:  Negative selection size");
  227.     exit(0);
  228.   }
  229.   if (size > 100000) 
  230.   {
  231.     sprintf(msg, "%.1f MB", size/1000000.0);
  232.   }
  233.   else 
  234.   {
  235.     sprintf(msg, "%.1f KB", size/1000.0);
  236.   }
  237.   Alert(dtr_mainWindow->selectionSizeMessage, msg);
  238. }
  239.  
  240.  
  241. /*
  242.  * Update file parameters on screen (due to the loading of a new file).
  243.  */
  244. void
  245.   UpdateMessageDisplay()
  246. {
  247.   DisplaySoundSize();
  248.   DisplaySoundSelectionSize();
  249.   DisplaySoundDuration();
  250.   DisplaySoundSelectionDuration();
  251. }
  252.  
  253.  
  254. /*
  255.  *  Update both the zoom level scrollbar and the zoom level text field.
  256.  */
  257. void
  258.   UpdateZoomLevelDisplay()
  259. {
  260.   xv_set(dtr_mainWindow->zoomSlider, PANEL_VALUE, 
  261.      irint(Zoom * 100.0), NULL);
  262.   sprintf(msg, "%.2lf", Zoom);
  263.   xv_set(dtr_mainWindow->zoomLevelTextField, 
  264.      PANEL_VALUE, msg, NULL);
  265. }
  266.  
  267.  
  268. void
  269.   UpdateSpaceOnTmp()
  270. {
  271.   struct statfs *statfsbuf;
  272.   int           totalsecs;
  273.   int           min;
  274.   double        sec;
  275.   int           avail;
  276.   int           availPercent;
  277.   
  278.   statfsbuf = (struct statfs *) malloc(sizeof(struct statfs));
  279.   
  280.   if (statfs("/usr/tmp", statfsbuf) == -1)
  281.   {
  282.     fprintf(stderr, "Can't do statfs on /usr/tmp.\n");
  283.     exit(0);
  284.   }
  285.  
  286.   avail = statfsbuf->f_bsize * statfsbuf->f_bavail  / 1000;        
  287.   totalsecs = irint(avail * 1000.0 / ((double) DEVICE_SAMPLE_RATE));
  288.   min = irint(floor(totalsecs / 60.0));
  289.   sec = totalsecs - (60.0 * min);
  290.   
  291.   if (avail / 1000.0 > 1.0)
  292.   {
  293.     sprintf(msg, "  %d min %.1lf sec.  (%.3lf MB)", min, sec, avail/1000.0);
  294.   }
  295.   else
  296.   {
  297.     sprintf(msg, "  %d min %.1lf sec.  (%d KB)", min, sec, avail);
  298.   }
  299.   
  300.   xv_set(dtr_mainWindow->spaceLeftOnTmpMessage, PANEL_LABEL_STRING, msg, NULL);
  301. }
  302.  
  303.   
  304. void
  305.   UpdateButtonGlow()
  306. {
  307.   static short count = 0;
  308.   
  309.   if (count == 0)
  310.   {
  311.     count = 1;
  312.     if (ActiveFlag & PLAY)
  313.     {
  314.       xv_set(dtr_mainWindow->playButton, PANEL_ITEM_COLOR, GreenColorIndex, NULL);
  315.     }
  316.     else if (ActiveFlag & RECORD)
  317.     {
  318.       xv_set(dtr_mainWindow->recordButton, PANEL_ITEM_COLOR, RedColorIndex, NULL);
  319.     }
  320.  
  321.   }
  322.   else
  323.   {
  324.     count = 0;
  325.     if (ActiveFlag & PLAY)
  326.     {
  327.       xv_set(dtr_mainWindow->playButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  328.     }
  329.     else if (ActiveFlag & RECORD)
  330.     {
  331.       xv_set(dtr_mainWindow->recordButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  332.     }
  333.  
  334.   }
  335. }    
  336.  
  337.  
  338. void
  339.   CancelButtonGlow()
  340. {
  341.   xv_set(dtr_mainWindow->playButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  342.   xv_set(dtr_mainWindow->recordButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  343.   xv_set(dtr_mainWindow->pauseButton, PANEL_ITEM_COLOR, BlackColorIndex, NULL);
  344. }  
  345.  
  346.  
  347. void
  348.   UpdateRecordingMessageDisplay()
  349. {
  350.   UpdateSpaceOnTmp();
  351.   DisplaySoundSize();
  352.   DisplaySoundDuration();
  353. }
  354.